//
// Created by vcq on 21/2/25.
//
#pragma once
#include "utils_dao.hpp"
#include <string>
#include "dbng.hpp"
#include "model/course.hpp"
#include "model/_finishrequire_goal.hpp"
#include "model/_teachgoal_judge.hpp"
#include "model/teachgoal.hpp"
#include "model/_require_syllabus.hpp"
#include "model/_syllabus_teachgoal.hpp"
#include "model/goal.hpp"
using namespace nlohmann;
using namespace std;
static void GetSyllabus(request& req, response& res) {
    if (!check_login(req, res)) {
        return;
    }
    basic_string_view<char> id = req.get_query_value("id");
    basic_string_view<char> _plan_id = req.get_query_value("_plan_id");
    vector<string> ids;
    if (id == _plan_id && _plan_id == "") {
        ids = check_syllabus(req, res);
    }
    json item = MGetSyllabusData(id, _plan_id, ids);
    res.set_status_and_content(status_type::ok, item.dump(), req_content_type::json);
}

static void SaveSyllabus(request& req, response& res) {
    if(!check_login(req,res)){
        return;
    }
    struct syllabus syllabus1{};
    syllabus1.id = atoi(req.get_query_value("id").data());
    syllabus1.name=req.get_query_value("name");
    syllabus1._grade_id=atoi(req.get_query_value("_grade_id").data());
    syllabus1._course_id=atoi(req.get_query_value("_course_id").data());
    syllabus1._plan_id=atoi(req.get_query_value("_plan_id").data());
    syllabus1.note=req.get_query_value("note");
    MSaveSyllabus(syllabus1);
    res.set_status_and_content(status_type::ok);
}
static void DeleteSyllabus(request& req, response& res) {
    if(!check_login(req,res)){
        return;
    }
    MDeleteSyllabus(req.get_query_value("id"));
    res.set_status_and_content(status_type::ok);
}